package com.example.zp.liaotian;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.jbmsuppliers.R;

import java.util.ArrayList;

/**
 * Created by donar_work on 2017/3/9.
 */

public class Buddy_ListAdapter extends RecyclerView.Adapter<Buddy_ListAdapter.ViewHolder> {
    ViewHolder holder = null;
    Context mContext;
    private LayoutInflater inflater;
    private ArrayList<Buddy_ListData> mData;
    private int local_id;
    public Buddy_ListAdapter(Context mContext , ArrayList<Buddy_ListData> mData,int local_id){
        this.mContext = mContext;
        this.mData = mData;
        this.local_id = local_id;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(inflater.inflate(R.layout.buddy_list_text, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        Buddy_ListData buddy_listData = mData.get(position);
        holder.t_ID.setText(buddy_listData.getM_account_id()+"");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                int t_ID = mData.get(position).getM_account_id();
                bundle.putInt("t_ID",t_ID);
                bundle.putInt("local_id",local_id);
                intent.putExtras(bundle);
                intent.setClass(mContext,Personal_InformationActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);
            }
        });
    }

//    @Override
//    public long getItemId(int position) {
//        return position;
//    }

    @Override
    public int getItemCount() {
        return mData != null ? mData.size() : 0;
    }

   /* @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            holder = new Buddy_ListAdapter.ViewHolder();
            convertView = View.inflate(mContext,R.layout.buddy_list_text,null);
            holder.t_ID = (TextView) convertView.findViewById(R.id.t_ID);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.t_ID.setText(mData.get(position).getM_account_id()+"");
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                int t_ID = mData.get(position).getM_account_id();
                bundle.putInt("t_ID",t_ID);
                bundle.putInt("local_id",local_id);
                intent.putExtras(bundle);
                intent.setClass(mContext,MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }*/
    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView t_ID;

        public ViewHolder(View itemView) {
            super(itemView);
            t_ID = (TextView) itemView.findViewById(R.id.t_ID);
        }
    }
}
